*************************************************************************************************
*************************************************************************************************
**********Name: Gerald L. McCallister                                                       *****                      
**********Article: Beyond Dyads: Regional Democratic Strength's Influence on Dyadic Conflict*****
**********Statement: This is the code I used to create my data for my Beyond Dyads paper and*****
********** produce my tables and figures.  I began this during grad school, and I realize   *****
**********some of the code may be gratuitous or unecessary, but it is included to reproduce *****
**********my results the same way I did it. I have my own personal file names for the data  *****
********** listed below.  Data includes dyads and years from...                             *****
********** Barbieri et al. (2009) trade data."dyadic_data"                                  *****
**********Marshal et. al (2010) Polity 2012 data is 2 files for dyadic data "pol1" and "pol2" ***
**********Ghosn et. al. (2003) COW MID data v.3.1 "dyadmid20"; Stinnett et al.(2002)Contiguity***
**********v.3 "contiguity_2011"; Composite Index of National Capabilities v.4.0 in 2 files  *****
**********for dyads by Singer (1987) "military_capability1" & "military_capability2"; and   *****
**********Maoz's MID data (2005) "dyadicmid2.0MAOZ.dta"; Hensel (2001) territorial issue data****
********** "dyadic_terriss".                                                                *****
*************************************************************************************************
*************************************************************************************************

**I kept the country codes, names of countries and years from Barbieri's trade data since it covered all the cases I needed.**
**Barbieri, Katherine, Omar M. G. Keshk, and Brian Pollins. �TRADING DATA: Evaluating our Assumptions and Coding Rules.� Conflict Management and Peace Science 26:471-491.**

use dyadic_data

save regdemE, replace

**COW MID Data Ghosn, Faten, and Stuart Bremer (2003) Codebook for the Dyadic Militarized Interstate Incident Data, Version 3.10: http://correlatesofwar.org.**
**Ghosn, Faten, Glenn Palmer, and Stuart Bremer (2004) The MID3 Data Set, 1993�2001: Procedures, Coding Rules, and Description. Conflict Management and Peace Science 21:133-154**

use dyadmid20

sort ccode1 ccode2 year

save dyadmid20E, replace

use regdemE

sort ccode1 ccode2 year

merge ccode1 ccode2 year using dyadmid20E

drop _merge

save regdemE, replace

**contiguity Stinnett, Douglas M., Jaroslav Tir, Philip Schafer, Paul F. Diehl, and Charles Gochman. (2002) The Correlates of War Project Direct Contiguity Data, Version 3 Conflict Mangagement and Peace Science 19 (2): 58-66.**

use contiguity_2011

**drop duplicates**

sort ccode1 ccode2 year

unab vlist : _all

sort `vlist'

quietly by `vlist': gen dup = cond(_N==1, 0, _n)

count if dup>1

drop if dup>1

sort ccode1 ccode2 year

save contiguity_2011E, replace

use regdemE

sort ccode1 ccode2 year

merge ccode1 ccode2 year using contiguity_2011E

save regdemE, replace

**Polity scores Marshall, Monty G., Keith Jaggers, and Ted Robert Gurr. (2010) Polity IV Project, Political Regime Characteristics and Transitions, 1800-2010: http://www.systemicpeace.org/polity/polity4.htm**
**I have 2 versions of the Polity data to merge into dyadic data. In pol1, I put a "1" after each variable of interest except polity2, which I put an "A" after; in pol2, I put a "2" or "B" after the respective variables." 

use pol1

sort ccode1 year

save pol1, replace

use regdemE

sort ccode1 year

drop _merge

merge ccode1 year using pol1

save regdemE, replace

use pol2

sort ccode2 year

save pol2, replace

use regdemE

sort ccode2 year

drop _merge

merge ccode2 year using pol2

save regdemE, replace

**COW CINC scores: Singer, J. David. (1987) Reconstructing the Correlates of War Dataset on Material Capabilities of States, 1816-1985. International Interactions 14: 115-32.
**Singer, J. David, Stuart Bremer, and John Stuckey (1972) Capability Distribution, Uncertainty, and Major Power War, 1820-1965. in Bruce Russett (ed) Peace, War, and Numbers, Beverly Hills: Sage, 19-48.**
**I have 2 versions of the CINC data to merge into dyadic data. In military_capability1, I put a "1" after each variable of interest; in military_capability2, I put a "2" after the respective variables." 

use military_capability1

sort ccode1 year

save military_capability1, replace

use regdemE

sort ccode1 year

drop _merge

merge ccode1 year using military_capability1

save regdemE, replace

use military_capability2

sort ccode2 year

save military_capability2, replace

use regdemE

sort ccode2 year

drop _merge

merge ccode2 year using military_capability2

save regdemE, replace

drop disno strtday strtmnth strtyr endday endmnth endyear outcome settlmnt recip noinit notarg sideaa revstata revtypea fataleva highmcaa hihosta orignata sideab revstateb revtypeb fatalevb highmcab hihostb orignatb rolea roleb durindx highact mid3hiact mid3hia mid3hib irst1 milex1 milper1 energy1 tpop1 upop1 irst2 milex2 milper2 energy2 tpop2 upop2 _merge

replace polity2a = 0 if democ1==-66

replace polity2b = 0 if democ2==-66

replace fatlev = 0 if fatlev==.

replace hihost = 0 if hihost==.

replace war = 0 if war==.

replace conttype = 6 if conttype==.

save regdemE, replace

**Use my polity data and Lemke's (2002) regional groupings to generate continental and regional codes**

use pol1

drop democ1  autoc1 polity2a change1

save regions1E, replace

gen North_America1 = 0

replace North_America1 = 1 if ccode1== 2

replace North_America1 = 1 if ccode1== 20

replace North_America1 = 1 if ccode1== 40

replace North_America1 = 1 if ccode1== 41

replace North_America1 = 1 if ccode1== 42

replace North_America1 = 1 if ccode1== 51

replace North_America1 = 1 if ccode1== 52

replace North_America1 = 1 if ccode1== 70

replace North_America1 = 1 if ccode1== 90

replace North_America1 = 1 if ccode1== 91

replace North_America1 = 1 if ccode1== 92

replace North_America1 = 1 if ccode1== 93

replace North_America1 = 1 if ccode1== 94

replace North_America1 = 1 if ccode1== 95

gen South_America1 = 0

replace South_America1 = 1 if ccode1== 100

replace South_America1 = 1 if ccode1== 101

replace South_America1 = 1 if ccode1== 110

replace South_America1 = 1 if ccode1== 130

replace South_America1 = 1 if ccode1== 135

replace South_America1 = 1 if ccode1== 140

replace South_America1 = 1 if ccode1== 145

replace South_America1 = 1 if ccode1== 150

replace South_America1 = 1 if ccode1== 155

replace South_America1 = 1 if ccode1== 160

replace South_America1 = 1 if ccode1== 165

gen Europe1 = 0

replace Europe1 = 1 if ccode1== 200

replace Europe1 = 1 if ccode1== 205

replace Europe1 = 1 if ccode1== 210

replace Europe1 = 1 if ccode1== 211

replace Europe1 = 1 if ccode1== 220

replace Europe1 = 1 if ccode1== 225

replace Europe1 = 1 if ccode1== 230

replace Europe1 = 1 if ccode1== 235

replace Europe1 = 1 if ccode1== 255

replace Europe1 = 1 if ccode1== 260

replace Europe1 = 1 if ccode1== 265

replace Europe1 = 1 if ccode1== 290

replace Europe1 = 1 if ccode1== 305

replace Europe1 = 1 if ccode1== 310

replace Europe1 = 1 if ccode1== 315

replace Europe1 = 1 if ccode1== 316

replace Europe1 = 1 if ccode1== 317

replace Europe1 = 1 if ccode1== 325

replace Europe1 = 1 if ccode1== 339

replace Europe1 = 1 if ccode1== 342

replace Europe1 = 1 if ccode1== 343

replace Europe1 = 1 if ccode1== 344

replace Europe1 = 1 if ccode1== 345

replace Europe1 = 1 if ccode1== 346

replace Europe1 = 1 if ccode1== 347

replace Europe1 = 1 if ccode1== 349

replace Europe1 = 1 if ccode1== 350

replace Europe1 = 1 if ccode1== 352

replace Europe1 = 1 if ccode1== 355

replace Europe1 = 1 if ccode1== 359

replace Europe1 = 1 if ccode1== 360

replace Europe1 = 1 if ccode1== 364

replace Europe1 = 1 if ccode1== 365

replace Europe1 = 1 if ccode1== 366

replace Europe1 = 1 if ccode1== 367

replace Europe1 = 1 if ccode1== 368

replace Europe1 = 1 if ccode1== 369

replace Europe1 = 1 if ccode1== 370

replace Europe1 = 1 if ccode1== 375

replace Europe1 = 1 if ccode1== 380

replace Europe1 = 1 if ccode1== 385

replace Europe1 = 1 if ccode1== 390

gen Africa1 = 0

replace Africa1 = 1 if ccode1== 404

replace Africa1 = 1 if ccode1== 411

replace Africa1 = 1 if ccode1== 420

replace Africa1 = 1 if ccode1== 432

replace Africa1 = 1 if ccode1== 433

replace Africa1 = 1 if ccode1== 434

replace Africa1 = 1 if ccode1== 435

replace Africa1 = 1 if ccode1== 436

replace Africa1 = 1 if ccode1== 437

replace Africa1 = 1 if ccode1== 438

replace Africa1 = 1 if ccode1== 439

replace Africa1 = 1 if ccode1== 450

replace Africa1 = 1 if ccode1== 451

replace Africa1 = 1 if ccode1== 452

replace Africa1 = 1 if ccode1== 461

replace Africa1 = 1 if ccode1== 471

replace Africa1 = 1 if ccode1== 475

replace Africa1 = 1 if ccode1== 481

replace Africa1 = 1 if ccode1== 482

replace Africa1 = 1 if ccode1== 483

replace Africa1 = 1 if ccode1== 484

replace Africa1 = 1 if ccode1== 490

replace Africa1 = 1 if ccode1== 500

replace Africa1 = 1 if ccode1== 501

replace Africa1 = 1 if ccode1== 510

replace Africa1 = 1 if ccode1== 516

replace Africa1 = 1 if ccode1== 517

replace Africa1 = 1 if ccode1== 520

replace Africa1 = 1 if ccode1== 522
 
replace Africa1 = 1 if ccode1== 529

replace Africa1 = 1 if ccode1== 530

replace Africa1 = 1 if ccode1== 531

replace Africa1 = 1 if ccode1== 540

replace Africa1 = 1 if ccode1== 541

replace Africa1 = 1 if ccode1== 551

replace Africa1 = 1 if ccode1== 552

replace Africa1 = 1 if ccode1== 553

replace Africa1 = 1 if ccode1== 560

replace Africa1 = 1 if ccode1== 564

replace Africa1 = 1 if ccode1== 565

replace Africa1 = 1 if ccode1== 570

replace Africa1 = 1 if ccode1== 571

replace Africa1 = 1 if ccode1== 572

replace Africa1 = 1 if ccode1== 580

replace Africa1 = 1 if ccode1== 581

replace Africa1 = 1 if ccode1== 590

replace Africa1 = 1 if ccode1== 600

replace Africa1 = 1 if ccode1== 615

replace Africa1 = 1 if ccode1== 616

replace Africa1 = 1 if ccode1== 620

replace Africa1 = 1 if ccode1== 625

gen Middle_East1 = 0

replace Middle_East1 = 1 if ccode1== 651

replace Middle_East1 = 1 if ccode1== 630

replace Middle_East1 = 1 if ccode1== 640

replace Middle_East1 = 1 if ccode1== 645

replace Middle_East1 = 1 if ccode1== 652

replace Middle_East1 = 1 if ccode1== 660

replace Middle_East1 = 1 if ccode1== 663

replace Middle_East1 = 1 if ccode1== 666

replace Middle_East1 = 1 if ccode1== 670

replace Middle_East1 = 1 if ccode1== 678

replace Middle_East1 = 1 if ccode1== 679

replace Middle_East1 = 1 if ccode1== 680

replace Middle_East1 = 1 if ccode1== 690

replace Middle_East1 = 1 if ccode1== 692

replace Middle_East1 = 1 if ccode1== 694

replace Middle_East1 = 1 if ccode1== 696

replace Middle_East1 = 1 if ccode1== 698

gen Far_East1 = 0

replace Far_East1 = 1 if ccode1== 371

replace Far_East1 = 1 if ccode1== 372

replace Far_East1 = 1 if ccode1== 373

replace Far_East1 = 1 if ccode1== 700

replace Far_East1 = 1 if ccode1== 701

replace Far_East1 = 1 if ccode1== 702
 
replace Far_East1 = 1 if ccode1== 703

replace Far_East1 = 1 if ccode1== 704

replace Far_East1 = 1 if ccode1== 705

replace Far_East1 = 1 if ccode1== 710

replace Far_East1 = 1 if ccode1== 712

replace Far_East1 = 1 if ccode1== 713

replace Far_East1 = 1 if ccode1== 731

replace Far_East1 = 1 if ccode1== 732

replace Far_East1 = 1 if ccode1== 750

replace Far_East1 = 1 if ccode1== 760

replace Far_East1 = 1 if ccode1== 769

replace Far_East1 = 1 if ccode1== 770

replace Far_East1 = 1 if ccode1== 771

replace Far_East1 = 1 if ccode1== 775

replace Far_East1 = 1 if ccode1== 780

replace Far_East1 = 1 if ccode1== 790

replace Far_East1 = 1 if ccode1== 800

replace Far_East1 = 1 if ccode1== 811

replace Far_East1 = 1 if ccode1== 812

replace Far_East1 = 1 if ccode1== 816

replace Far_East1 = 1 if ccode1== 817

replace Far_East1 = 1 if ccode1== 818

replace Far_East1 = 1 if ccode1== 820

replace Far_East1 = 1 if ccode1== 830

replace Far_East1 = 1 if ccode1== 840

replace Far_East1 = 1 if ccode1== 850

replace Far_East1 = 1 if ccode1== 900

replace Far_East1 = 1 if ccode1== 910

replace Far_East1 = 1 if ccode1== 920

replace Far_East1 = 1 if ccode1== 940

replace Far_East1 = 1 if ccode1== 950

replace Far_East1 = 1 if ccode1== 364

replace Far_East1 = 1 if ccode1== 365

gen Northern_Tier1 = 0

replace Northern_Tier1 = 1 if ccode1== 100

replace Northern_Tier1 = 1 if ccode1== 101

replace Northern_Tier1 = 1 if ccode1== 130

gen Atlantic_Coast1 = 0

replace Atlantic_Coast1 = 1 if ccode1== 140

replace Atlantic_Coast1 = 1 if ccode1== 160

replace Atlantic_Coast1 = 1 if ccode1== 165

gen Pacific_Coast1 = 0

replace Pacific_Coast1 = 1 if ccode1== 135

replace Pacific_Coast1 = 1 if ccode1== 155

gen Central1 = 0

replace Central1 = 1 if ccode1== 145

replace Central1 = 1 if ccode1== 150

gen Arab_Israeli1 = 0

replace Arab_Israeli1 = 1 if ccode1== 645

replace Arab_Israeli1 = 1 if ccode1== 651

replace Arab_Israeli1 = 1 if ccode1== 652

replace Arab_Israeli1 = 1 if ccode1== 660

replace Arab_Israeli1 = 1 if ccode1== 663

replace Arab_Israeli1 = 1 if ccode1== 666

gen Northern_Rim1 = 0

replace Northern_Rim1 = 1 if ccode1== 630

replace Northern_Rim1 = 1 if ccode1== 640

replace Northern_Rim1 = 1 if ccode1== 645

gen Arabian_Peninsula1 = 0

replace Arabian_Peninsula1 = 1 if ccode1== 670

replace Arabian_Peninsula1 = 1 if ccode1== 690

replace Arabian_Peninsula1 = 1 if ccode1== 692

replace Arabian_Peninsula1 = 1 if ccode1== 694

replace Arabian_Peninsula1 = 1 if ccode1== 696

gen South_Asia1 = 0

replace South_Asia1 = 1 if ccode1== 750

replace South_Asia1 = 1 if ccode1== 760

replace South_Asia1 = 1 if ccode1== 769

replace South_Asia1 = 1 if ccode1== 771 

gen Southeast_Asia1 = 0

replace Southeast_Asia1 = 1 if ccode1== 800

replace Southeast_Asia1 = 1 if ccode1== 811

replace Southeast_Asia1 = 1 if ccode1== 812

replace Southeast_Asia1 = 1 if ccode1== 816

replace Southeast_Asia1 = 1 if ccode1== 817

replace Southeast_Asia1 = 1 if ccode1== 818

gen East_Asia1 = 0

replace East_Asia1 = 1 if ccode1== 710

replace East_Asia1 = 1 if ccode1== 712

replace East_Asia1 = 1 if ccode1== 713

replace East_Asia1 = 1 if ccode1== 731

replace East_Asia1= 1 if ccode1== 732

replace East_Asia1 = 1 if ccode1== 740

gen Asian_Archipelago1 = 0

replace Asian_Archipelago1 = 1 if ccode1== 820

replace Asian_Archipelago1 = 1 if ccode1== 830

replace Asian_Archipelago1 = 1 if ccode1== 850

gen AfgPak1 = 0

replace AfgPak1 = 1 if ccode1== 700 

replace AfgPak1 = 1 if ccode1== 769

gen BurmThai1 = 0

replace BurmThai1 = 1 if ccode1== 775

replace BurmThai1 = 1 if ccode1== 800

gen Koreas1 = 0

replace Koreas1 = 1 if ccode1== 731

replace Koreas1 = 1 if ccode1== 732

gen Maghreb1 = 0

replace Maghreb1 = 1 if ccode1== 600

replace Maghreb1 = 1 if ccode1== 615

replace Maghreb1 = 1 if ccode1== 616

replace Maghreb1 = 1 if ccode1== 620 

gen West_Africa1 = 0

replace West_Africa1 = 1 if ccode1== 404

replace West_Africa1 = 1 if ccode1== 420

replace West_Africa1 = 1 if ccode1== 432

replace West_Africa1 = 1 if ccode1== 433

replace West_Africa1 = 1 if ccode1== 435

replace West_Africa1 = 1 if ccode1== 438

replace West_Africa1 = 1 if ccode1== 451

gen Gulf_of_Guinea1 = 0

replace Gulf_of_Guinea1 = 1 if ccode1== 434

replace Gulf_of_Guinea1 = 1 if ccode1== 436

replace Gulf_of_Guinea1 = 1 if ccode1== 437 

replace Gulf_of_Guinea1 = 1 if ccode1== 439

replace Gulf_of_Guinea1 = 1 if ccode1== 450

replace Gulf_of_Guinea1 = 1 if ccode1== 452

replace Gulf_of_Guinea1 = 1 if ccode1== 461

replace Gulf_of_Guinea1 = 1 if ccode1== 471

replace Gulf_of_Guinea1 = 1 if ccode1== 475

gen Central_Lowlands1 = 0

replace Central_Lowlands1 = 1 if ccode1== 482

replace Central_Lowlands1 = 1 if ccode1== 483

gen Horn_of_Africa1 = 0

replace Horn_of_Africa1 = 1 if ccode1== 520

replace Horn_of_Africa1 = 1 if ccode1== 522

replace Horn_of_Africa1 = 1 if ccode1== 529

replace Horn_of_Africa1 = 1 if ccode1== 625

gen Central_Highlands1 = 0

replace Central_Highlands1 = 1 if ccode1== 516

replace Central_Highlands1 = 1 if ccode1== 517

gen South_Atlantic_Coast1 = 0

replace South_Atlantic_Coast1 = 1 if ccode1== 471

replace South_Atlantic_Coast1 = 1 if ccode1== 481

replace South_Atlantic_Coast1 = 1 if ccode1== 484

replace South_Atlantic_Coast1 = 1 if ccode1== 490

replace South_Atlantic_Coast1 = 1 if ccode1== 540

gen Indian_Ocean1 = 0

replace Indian_Ocean1 = 1 if ccode1== 500

replace Indian_Ocean1 = 1 if ccode1== 501

replace Indian_Ocean1 = 1 if ccode1== 510

gen Southern_Africa1 = 0

replace Southern_Africa1 = 1 if ccode1== 541

replace Southern_Africa1 = 1 if ccode1== 551

replace Southern_Africa1 = 1 if ccode1== 552

replace Southern_Africa1 = 1 if ccode1== 553

replace Southern_Africa1 = 1 if ccode1== 560

replace Southern_Africa1 = 1 if ccode1== 570

replace Southern_Africa1 = 1 if ccode1== 571

replace Southern_Africa1 = 1 if ccode1== 572

drop scode2

save regions1E, replace

**generate a second regions dataset**

rename ccode1 ccode2

rename country1 country2

rename North_America1 North_America2

rename South_America1 South_America2

rename Europe1 Europe2

rename Africa1 Africa2

rename Middle_East1 Middle_East2

rename Far_East1 Far_East2 

rename Northern_Tier1 Northern_Tier2

rename Atlantic_Coast1 Atlantic_Coast2

rename Pacific_Coast1 Pacific_Coast2

rename Central1 Central2

rename Arab_Israeli1 Arab_Israeli2

rename Northern_Rim1 Northern_Rim2

rename Arabian_Peninsula1 Arabian_Peninsula2

rename South_Asia1 South_Asia2

rename Southeast_Asia1 Southeast_Asia2

rename East_Asia1 East_Asia2

rename Asian_Archipelago1 Asian_Archipelago2

rename AfgPak1 AfgPak2

rename BurmThai1 BurmThai2

rename Koreas1 Koreas2

rename Maghreb1 Maghreb2

rename West_Africa1 West_Africa2

rename Gulf_of_Guinea1 Gulf_of_Guinea2

rename Central_Lowlands1 Central_Lowlands2

rename Horn_of_Africa1 Horn_of_Africa2

rename Central_Highlands1 Central_Highlands2

rename South_Atlantic_Coast1 South_Atlantic_Coast2

rename Indian_Ocean1 Indian_Ocean2

rename Southern_Africa1 Southern_Africa2

save regions2E, replace

**merge regions datasets to main dataset**

use regions1E

sort ccode1 year

save regions1E, replace

use regdemE

sort ccode1 year

merge ccode1 year using regions1E

save regdemE, replace

use regions2E

sort ccode2 year

save regions2E, replace

use regdemE

sort ccode2 year

drop _merge

merge ccode2 year using regions2E

save regdemE, replace

**drop observations with insufficient data**

drop if cinc1==. 

drop if cinc2==.

drop if polity2a==.

drop if polity2b==.

**generate dyadic regional variables**

gen North_America = 0

replace North_America = 1 if North_America1==1 & North_America2==1

gen South_America = 0

replace South_America = 1 if South_America1==1 & South_America2==1

gen Europe = 0

replace Europe = 1 if Europe1==1 & Europe2==1

gen Africa = 0

replace Africa = 1 if Africa1==1 & Africa2==1

gen Middle_East = 0

replace Middle_East = 1 if Middle_East1==1 & Middle_East2==1

gen Far_East = 0

replace Far_East = 1 if Far_East1==1 & Far_East2==1 

gen Northern_Tier = 0

replace Northern_Tier = 1 if Northern_Tier1==1 & Northern_Tier2==1

gen Atlantic_Coast = 0

replace Atlantic_Coast = 1 if Atlantic_Coast1==1 & Atlantic_Coast2==1

gen Pacific_Coast = 0

replace Pacific_Coast = 1 if Pacific_Coast1==1 & Pacific_Coast2==1

gen Central = 0

replace Central = 1 if Central1==1 & Central2==1

gen Arab_Israeli = 0

replace Arab_Israeli = 1 if Arab_Israeli1==1 & Arab_Israeli2==1

gen Northern_Rim = 0

replace Northern_Rim = 1 if Northern_Rim1==1 & Northern_Rim2==1

gen Arabian_Peninsula = 0

replace Arabian_Peninsula= 1 if Arabian_Peninsula1==1 & Arabian_Peninsula2==1

gen South_Asia = 0

replace South_Asia = 1 if South_Asia1==1 & South_Asia2==1

gen Southeast_Asia = 0

replace Southeast_Asia = 1 if Southeast_Asia1==1 & Southeast_Asia2==1

gen East_Asia = 0

replace East_Asia = 1 if East_Asia1==1 & East_Asia2==1

gen Asian_Archipelago = 0

replace Asian_Archipelago = 1 if Asian_Archipelago1==1 & Asian_Archipelago2==1

gen BurmThai = 0

replace BurmThai = 1 if BurmThai1==1 & BurmThai2==1

gen Koreas = 0

replace Koreas = 1 if Koreas1==1 & Koreas2==1

gen Maghreb = 0

replace Maghreb = 1 if Maghreb1==1 & Maghreb2==1

gen West_Africa = 0

replace West_Africa = 1 if West_Africa1==1 & West_Africa2==1

gen Gulf_of_Guinea = 0

replace Gulf_of_Guinea = 1 if Gulf_of_Guinea1==1 & Gulf_of_Guinea2==1

gen Central_Lowlands = 0

replace Central_Lowlands = 1 if Central_Lowlands1==1 & Central_Lowlands2==1

gen Horn_of_Africa = 0

replace Horn_of_Africa = 1 if Horn_of_Africa1==1 & Horn_of_Africa2==1

gen Central_Highlands = 0

replace Central_Highlands = 1 if Central_Highlands1==1 & Central_Highlands2==1

gen South_Atlantic_Coast = 0

replace South_Atlantic_Coast = 1 if South_Atlantic_Coast1==1 & South_Atlantic_Coast2==1

gen Indian_Ocean = 0

replace Indian_Ocean = 1 if Indian_Ocean1==1 & Indian_Ocean2==1

gen Southern_Africa = 0

replace Southern_Africa = 1 if Southern_Africa1==1 & Southern_Africa2==1

drop North_America1 North_America2 South_America1 South_America2 Europe1 Europe2 Africa1 Africa2 Middle_East1 Middle_East2 Far_East1 Far_East2 Northern_Tier1 Northern_Tier2 Atlantic_Coast1 Atlantic_Coast2 Pacific_Coast1 Pacific_Coast2 Central1 Central2 Arab_Israeli1 Arab_Israeli2 Northern_Rim1 Northern_Rim2 Arabian_Peninsula1 Arabian_Peninsula2 South_Asia1 South_Asia2 Southeast_Asia1 Southeast_Asia2 East_Asia1 East_Asia2 Asian_Archipelago1 Asian_Archipelago2 AfgPak1 AfgPak2 BurmThai1 BurmThai2 Koreas1 Koreas2 Maghreb1 Maghreb2 West_Africa1 West_Africa2 Gulf_of_Guinea1 Gulf_of_Guinea2 Central_Lowlands1 Central_Lowlands2 Horn_of_Africa1 Horn_of_Africa2 Central_Highlands1 Central_Highlands2 South_Atlantic_Coast1 South_Atlantic_Coast2 Indian_Ocean1 Indian_Ocean2 Southern_Africa1 Southern_Africa2 _merge

save regdemE, replace

**gen regional CINC scores**

use regions1E

sort ccode1 year

save regions1E, replace

use military_capability1

drop irst1 milex1 milper1 energy1 tpop1 upop1

sort ccode1 year

merge ccode1 year using regions1E

save regionalCINCE, replace

drop _merge

drop if cinc1==.

gen North_AmericaCINC = cinc1 if North_America1==1

replace North_AmericaCINC = 0 if North_AmericaCINC==.

gen South_AmericaCINC = cinc1 if South_America1==1

replace South_AmericaCINC = 0 if South_AmericaCINC==.

gen EuropeCINC = cinc1 if Europe1==1

replace EuropeCINC = 0 if EuropeCINC==.

gen AfricaCINC = cinc1 if Africa1==1

replace AfricaCINC = 0 if AfricaCINC==.

gen Middle_EastCINC = cinc1 if Middle_East1==1

replace Middle_EastCINC = 0 if Middle_EastCINC==.

gen Far_EastCINC = cinc1 if Far_East1==1

replace Far_EastCINC = 0 if Far_EastCINC==.

gen Northern_TierCINC = cinc1 if Northern_Tier1==1

replace Northern_TierCINC  = 0 if Northern_TierCINC==.

gen Atlantic_CoastCINC = cinc1 if Atlantic_Coast1==1

replace Atlantic_CoastCINC = 0 if Atlantic_CoastCINC==.

gen Pacific_CoastCINC = cinc1 if Pacific_Coast1==1

replace Pacific_CoastCINC = 0 if Pacific_CoastCINC==.

gen CentralCINC = cinc1 if Central1==1

replace CentralCINC = 0 if CentralCINC==.

gen Arab_IsraeliCINC = cinc1 if Arab_Israeli1==1

replace Arab_IsraeliCINC = 0 if Arab_IsraeliCINC==.

gen Northern_RimCINC = cinc1 if Northern_Rim1==1

replace Northern_RimCINC = 0 if Northern_RimCINC==.

gen Arabian_PeninsulaCINC = cinc1 if Arabian_Peninsula1==1

replace Arabian_PeninsulaCINC = 0 if Arabian_PeninsulaCINC==.

gen South_AsiaCINC = cinc1 if South_Asia1==1

replace South_AsiaCINC = 0 if South_AsiaCINC==. 

gen Southeast_AsiaCINC = cinc1 if Southeast_Asia1==1

replace Southeast_AsiaCINC = 0 if Southeast_AsiaCINC==.

gen East_AsiaCINC = cinc1 if East_Asia1==1

replace East_AsiaCINC = 0 if East_AsiaCINC==.

gen Asian_ArchipelagoCINC = cinc1 if Asian_Archipelago1==1

replace Asian_ArchipelagoCINC = 0 if Asian_ArchipelagoCINC==.

gen BurmThaiCINC = cinc1 if BurmThai1==1

replace BurmThaiCINC = 0 if BurmThaiCINC==.

gen KoreasCINC = cinc1 if Koreas1==1

replace KoreasCINC = 0 if KoreasCINC==.

gen MaghrebCINC = cinc1 if Maghreb1==1

replace MaghrebCINC = 0 if MaghrebCINC==.

gen West_AfricaCINC = cinc1 if West_Africa1==1

replace West_AfricaCINC = 0 if West_AfricaCINC==.

gen Gulf_of_GuineaCINC = cinc1 if Gulf_of_Guinea1==1

replace Gulf_of_GuineaCINC = 0 if Gulf_of_GuineaCINC==.

gen Central_LowlandsCINC = cinc1 if Central_Lowlands1==1

replace Central_LowlandsCINC = 0 if Central_LowlandsCINC==.

gen Horn_of_AfricaCINC = cinc1 if Horn_of_Africa1==1

replace Horn_of_AfricaCINC = 0 if Horn_of_AfricaCINC==.

gen Central_HighlandsCINC = cinc1 if Central_Highlands1==1

replace Central_HighlandsCINC = 0 if Central_HighlandsCINC==.

gen South_Atlantic_CoastCINC = cinc1 if South_Atlantic_Coast1==1

replace South_Atlantic_CoastCINC = 0 if South_Atlantic_CoastCINC==.

gen Indian_OceanCINC = cinc1 if Indian_Ocean1==1

replace Indian_OceanCINC = 0 if Indian_OceanCINC==.

gen Southern_AfricaCINC = cinc1 if Southern_Africa1==1

replace Southern_AfricaCINC = 0 if Southern_AfricaCINC==.

**generate yearly CINC values for each region-country**

egen North_America_yearlyCINC = sum(North_AmericaCINC), by(year)

egen South_America_yearlyCINC = sum(South_AmericaCINC), by(year)

egen Europe_yearlyCINC = sum(EuropeCINC), by(year)

egen Africa_yearlyCINC = sum(AfricaCINC), by(year)

egen Middle_East_yearlyCINC = sum(Middle_EastCINC), by(year)

egen Far_East_yearlyCINC = sum(Far_EastCINC), by(year)

egen Northern_Tier_yearlyCINC = sum(Northern_TierCINC), by(year)

egen Atlantic_Coast_yearlyCINC = sum(Atlantic_CoastCINC), by(year)

egen Pacific_Coast_yearlyCINC = sum(Pacific_CoastCINC), by(year)

egen Central_yearlyCINC = sum(CentralCINC), by(year)

egen Arab_Israeli_yearlyCINC = sum(Arab_IsraeliCINC), by(year)

egen Northern_Rim_yearlyCINC = sum(Northern_RimCINC), by(year)

egen Arabian_Peninsula_yearlyCINC = sum(Arabian_PeninsulaCINC), by(year)

egen South_Asia_yearlyCINC = sum(South_AsiaCINC), by(year)

egen Southeast_Asia_yearlyCINC = sum(Southeast_AsiaCINC), by(year)

egen East_Asia_yearlyCINC = sum(East_AsiaCINC), by(year)

egen Asian_Archipelago_yearlyCINC = sum(Asian_ArchipelagoCINC), by(year)

egen BurmThai_yearlyCINC = sum(BurmThaiCINC), by(year)

egen Koreas_yearlyCINC = sum(KoreasCINC), by(year)

egen Maghreb_yearlyCINC = sum(MaghrebCINC), by(year)

egen West_Africa_yearlyCINC = sum(West_AfricaCINC), by(year)

egen Gulf_of_Guinea_yearlyCINC = sum(Gulf_of_GuineaCINC), by(year)

egen Central_Lowlands_yearlyCINC = sum(Central_LowlandsCINC), by(year)

egen Horn_of_Africa_yearlyCINC = sum(Horn_of_AfricaCINC), by(year)

egen Central_Highlands_yearlyCINC = sum(Central_HighlandsCINC), by(year)

egen South_Atlantic_Coast_yearlyCINC = sum(South_Atlantic_CoastCINC), by(year)

egen Indian_Ocean_yearlyCINC = sum(Indian_OceanCINC), by(year)

egen Southern_Africa_yearlyCINC = sum(Southern_AfricaCINC), by(year)

save regionalCINCE, replace

***Merge Polity data for weighting***

use pol1

drop country1

sort ccode1 year

save pol1aE, replace

use regionalCINCE

sort ccode1 year

merge ccode1 year using pol1aE

drop _merge change1

drop if polity2a==.

**Calculate each state's share**

gen North_AmericaStateCINC = cinc1/North_America_yearlyCINC*North_America1

gen South_AmericaStateCINC = cinc1/South_America_yearlyCINC*South_America1

gen EuropeStateCINC = cinc1/Europe_yearlyCINC*Europe1

gen AfricaStateCINC = cinc1/Africa_yearlyCINC*Africa1

gen Middle_EastStateCINC = cinc1/Middle_East_yearlyCINC*Middle_East1

gen Far_EastStateCINC = cinc1/Far_East_yearlyCINC*Far_East1

gen Northern_TierStateCINC = cinc1/Northern_Tier_yearlyCINC*Northern_Tier1

gen Atlantic_CoastStateCINC = cinc1/Atlantic_Coast_yearlyCINC*Atlantic_Coast1

gen Pacific_CoastStateCINC = cinc1/Pacific_Coast_yearlyCINC*Pacific_Coast1

gen CentralStateCINC = cinc1/Central_yearlyCINC*Central1

gen Arab_IsraeliStateCINC = cinc1/Arab_Israeli_yearlyCINC*Arab_Israeli1

gen Northern_RimStateCINC = cinc1/Northern_Rim_yearlyCINC*Northern_Rim1

gen Arabian_PeninsulaStateCINC = cinc1/Arabian_Peninsula_yearlyCINC*Arabian_Peninsula1

gen South_AsiaStateCINC = cinc1/South_Asia_yearlyCINC*South_Asia1

gen Southeast_AsiaStateCINC = cinc1/Southeast_Asia_yearlyCINC*Southeast_Asia1

gen East_AsiaStateCINC = cinc1/East_Asia_yearlyCINC*East_Asia1

gen Asian_ArchipelagoStateCINC = cinc1/Asian_Archipelago_yearlyCINC*Asian_Archipelago1

gen BurmThaiStateCINC = cinc1/BurmThai_yearlyCINC*BurmThai1

gen KoreasStateCINC = cinc1/Koreas_yearlyCINC*Koreas1

gen MaghrebStateCINC = cinc1/Maghreb_yearlyCINC*Maghreb1

gen West_AfricaStateCINC = cinc1/West_Africa_yearlyCINC*West_Africa1

gen Gulf_of_GuineaStateCINC = cinc1/Gulf_of_Guinea_yearlyCINC*Gulf_of_Guinea1

gen Central_LowlandsStateCINC = cinc1/Central_Lowlands_yearlyCINC*Central_Lowlands1

gen Horn_of_AfricaStateCINC = cinc1/Horn_of_Africa_yearlyCINC*Horn_of_Africa1

gen Central_HighlandsStateCINC = cinc1/Central_Highlands_yearlyCINC*Central_Highlands1

gen South_Atlantic_CoastStateCINC = cinc1/South_Atlantic_Coast_yearlyCINC*South_Atlantic_Coast1

gen Indian_OceanStateCINC = cinc1/Indian_Ocean_yearlyCINC*Indian_Ocean1

gen Southern_AfricaStateCINC = cinc1/Southern_Africa_yearlyCINC*Southern_Africa1

replace North_AmericaStateCINC = 0 if North_AmericaStateCINC==.

replace South_AmericaStateCINC = 0 if South_AmericaStateCINC==.

replace EuropeStateCINC = 0 if EuropeStateCINC==.

replace AfricaStateCINC = 0 if AfricaStateCINC==.

replace Middle_EastStateCINC = 0 if Middle_EastStateCINC==.

replace Far_EastStateCINC = 0 if Far_EastStateCINC==.

replace Northern_TierStateCINC = 0 if Northern_TierStateCINC==.

replace Atlantic_CoastStateCINC = 0 if Atlantic_CoastStateCINC==.

replace Pacific_CoastStateCINC = 0 if Pacific_CoastStateCINC==.

replace CentralStateCINC = 0 if CentralStateCINC==.

replace Arab_IsraeliStateCINC = 0 if Arab_IsraeliStateCINC==.

replace Northern_RimStateCINC = 0 if Northern_RimStateCINC==.

replace Arabian_PeninsulaStateCINC = 0 if Arabian_PeninsulaStateCINC==.

replace South_AsiaStateCINC = 0 if South_AsiaStateCINC==.

replace Southeast_AsiaStateCINC = 0 if Southeast_AsiaStateCINC==.

replace East_AsiaStateCINC = 0 if East_AsiaStateCINC==.

replace Asian_ArchipelagoStateCINC = 0 if Asian_ArchipelagoStateCINC==.

replace BurmThaiStateCINC = 0 if BurmThaiStateCINC==.

replace KoreasStateCINC = 0 if KoreasStateCINC==.

replace MaghrebStateCINC = 0 if MaghrebStateCINC==.

replace West_AfricaStateCINC = 0 if West_AfricaStateCINC==.

replace Gulf_of_GuineaStateCINC = 0 if Gulf_of_GuineaStateCINC==.

replace Central_LowlandsStateCINC = 0 if Central_LowlandsStateCINC==.

replace Horn_of_AfricaStateCINC = 0 if Horn_of_AfricaStateCINC==.

replace Central_HighlandsStateCINC = 0 if Central_HighlandsStateCINC==.

replace South_Atlantic_CoastStateCINC = 0 if South_Atlantic_CoastStateCINC==.

replace Indian_OceanStateCINC = 0 if Indian_OceanStateCINC==.

replace Southern_AfricaStateCINC = 0 if Southern_AfricaStateCINC==.

save regionalCINCE, replace

**Weight CINC scores**

gen WNorth_AmericaStateCINC = polity2a*North_AmericaStateCINC 

gen WSouth_AmericaStateCINC = polity2a*South_AmericaStateCINC

gen WEuropeStateCINC = polity2a*EuropeStateCINC

gen WAfricaStateCINC = polity2a*AfricaStateCINC

gen WMiddle_EastStateCINC = polity2a*Middle_EastStateCINC

gen WFar_EastStateCINC = polity2a*Far_EastStateCINC

gen WNorthern_TierStateCINC = polity2a*Northern_TierStateCINC

gen WAtlantic_CoastStateCINC = polity2a*Atlantic_CoastStateCINC

gen WPacific_CoastStateCINC = polity2a*Pacific_CoastStateCINC

gen WCentralStateCINC = polity2a*CentralStateCINC

gen WArab_IsraeliStateCINC = polity2a*Arab_IsraeliStateCINC

gen WNorthern_RimStateCINC = polity2a*Northern_RimStateCINC

gen WArabian_PeninsulaStateCINC = polity2a*Arabian_PeninsulaStateCINC

gen WSouth_AsiaStateCINC = polity2a*South_AsiaStateCINC

gen WSoutheast_AsiaStateCINC = polity2a*Southeast_AsiaStateCINC

gen WEast_AsiaStateCINC = polity2a*East_AsiaStateCINC

gen WAsian_ArchipelagoStateCINC = polity2a*Asian_ArchipelagoStateCINC

gen WBurmThaiStateCINC = polity2a*BurmThaiStateCINC

gen WKoreasStateCINC = polity2a*KoreasStateCINC

gen WMaghrebStateCINC = polity2a*MaghrebStateCINC

gen WWest_AfricaStateCINC = polity2a*West_AfricaStateCINC

gen WGulf_of_GuineaStateCINC = polity2a*Gulf_of_GuineaStateCINC

gen WCentral_LowlandsStateCINC = polity2a*Central_LowlandsStateCINC

gen WHorn_of_AfricaStateCINC = polity2a*Horn_of_AfricaStateCINC

gen WCentral_HighlandsStateCINC = polity2a*Central_HighlandsStateCINC

gen WSouth_Atlantic_CoastStateCINC = polity2a*South_Atlantic_CoastStateCINC

gen WIndian_OceanStateCINC = polity2a*Indian_OceanStateCINC

gen WSouthern_AfricaStateCINC = polity2a*Southern_AfricaStateCINC

save regionalCINCE, replace

**Create yearly weighted CINC scores for each region**

egen WNorth_America_yearlyCINC = sum(WNorth_AmericaStateCINC), by(year)

egen WSouth_America_yearlyCINC = sum(WSouth_AmericaStateCINC), by(year)

egen WEurope_yearlyCINC = sum(WEuropeStateCINC), by(year)

egen WAfrica_yearlyCINC = sum(WAfricaStateCINC), by(year)

egen WMiddle_East_yearlyCINC = sum(WMiddle_EastStateCINC), by(year)

egen WFar_East_yearlyCINC = sum(WFar_EastStateCINC), by(year)

egen WNorthern_Tier_yearlyCINC = sum(WNorthern_TierStateCINC), by(year)

egen WAtlantic_Coast_yearlyCINC = sum(WAtlantic_CoastStateCINC), by(year)

egen WPacific_Coast_yearlyCINC = sum(WPacific_CoastStateCINC), by(year)

egen WCentral_yearlyCINC = sum(WCentralStateCINC), by(year)

egen WArab_Israeli_yearlyCINC = sum(WArab_IsraeliStateCINC), by(year)

egen WNorthern_Rim_yearlyCINC = sum(WNorthern_RimStateCINC), by(year)

egen WArabian_Peninsula_yearlyCINC = sum(WArabian_PeninsulaStateCINC), by(year)

egen WSouth_Asia_yearlyCINC = sum(WSouth_AsiaStateCINC), by(year)

egen WSoutheast_Asia_yearlyCINC = sum(WSoutheast_AsiaStateCINC), by(year)

egen WEast_Asia_yearlyCINC = sum(WEast_AsiaStateCINC), by(year)

egen WAsian_Archipelago_yearlyCINC = sum(WAsian_ArchipelagoStateCINC), by(year)

egen WBurmThai_yearlyCINC = sum(WBurmThaiStateCINC), by(year)

egen WKoreas_yearlyCINC = sum(WKoreasStateCINC), by(year)

egen WMaghreb_yearlyCINC = sum(WMaghrebStateCINC), by(year)

egen WWest_Africa_yearlyCINC = sum(WWest_AfricaStateCINC), by(year)

egen WGulf_of_Guinea_yearlyCINC = sum(WGulf_of_GuineaStateCINC), by(year)

egen WCentral_Lowlands_yearlyCINC = sum(WCentral_LowlandsStateCINC), by(year)

egen WHorn_of_Africa_yearlyCINC = sum(WHorn_of_AfricaStateCINC), by(year)

egen WCentral_Highlands_yearlyCINC = sum(WCentral_HighlandsStateCINC), by(year)

egen WSouth_Atlantic_Coast_yearlyCINC = sum(WSouth_Atlantic_CoastStateCINC), by(year)

egen WIndian_Ocean_yearlyCINC = sum(WIndian_OceanStateCINC), by(year)

egen WSouthern_Africa_yearlyCINC = sum(WSouthern_AfricaStateCINC), by(year)
 
save regionalCINCE, replace

***Generate standardized score ranging from -1 to 1**

gen StNorth_America_yearlyCINC = WNorth_America_yearlyCINC*.1

gen StSouth_America_yearlyCINC = WSouth_America_yearlyCINC*.1

gen StEurope_yearlyCINC = WEurope_yearlyCINC*.1

gen StAfrica_yearlyCINC = WAfrica_yearlyCINC*.1

gen StMiddle_East_yearlyCINC = WMiddle_East_yearlyCINC*.1

gen StFar_East_yearlyCINC = WFar_East_yearlyCINC*.1

gen StNorthern_Tier_yearlyCINC = WNorthern_Tier_yearlyCINC*.1

gen StAtlantic_Coast_yearlyCINC = WAtlantic_Coast_yearlyCINC*.1

gen StPacific_Coast_yearlyCINC = WPacific_Coast_yearlyCINC*.1

gen StCentral_yearlyCINC = WCentral_yearlyCINC*.1

gen StArab_Israeli_yearlyCINC = WArab_Israeli_yearlyCINC*.1

gen StNorthern_Rim_yearlyCINC = WNorthern_Rim_yearlyCINC*.1

gen StArabian_Peninsula_yearlyCINC = WArabian_Peninsula_yearlyCINC*.1

gen StSouth_Asia_yearlyCINC = WSouth_Asia_yearlyCINC*.1

gen StSoutheast_Asia_yearlyCINC = WSoutheast_Asia_yearlyCINC*.1

gen StEast_Asia_yearlyCINC = WEast_Asia_yearlyCINC*.1

gen StAsian_Archipelago_yearlyCINC = WAsian_Archipelago_yearlyCINC*.1

gen StBurmThai_yearlyCINC = WBurmThai_yearlyCINC*.1

gen StKoreas_yearlyCINC = WKoreas_yearlyCINC*.1

gen StMaghreb_yearlyCINC = WMaghreb_yearlyCINC*.1

gen StWest_Africa_yearlyCINC = WWest_Africa_yearlyCINC*.1

gen StGulf_of_Guinea_yearlyCINC = WGulf_of_Guinea_yearlyCINC*.1

gen StCentral_Lowlands_yearlyCINC = WCentral_Lowlands_yearlyCINC*.1

gen StHorn_of_Africa_yearlyCINC = WHorn_of_Africa_yearlyCINC*.1

gen StCentral_Highlands_yearlyCINC = WCentral_Highlands_yearlyCINC*.1

gen StSouthAtlanticCoast_yearlyCINC = WSouth_Atlantic_Coast_yearlyCINC*.1

gen StIndian_Ocean_yearlyCINC = WIndian_Ocean_yearlyCINC*.1

gen StSouthern_Africa_yearlyCINC = WSouthern_Africa_yearlyCINC*.1

save regionalCINCE, replace

**labeling for future use**

label values North_America1 
label var North_America1 "What continent each observation belongs to"
label var Northern_Tier1 "What region each observation belongs to"
label var North_AmericaCINC "CINC score if observation belongs to region or coninent"
label var North_America_yearlyCINC "Percentage of CINC scores belonging to this continent/region this year"
label var North_AmericaStateCINC "Percentage of continent/region's CINC belonging to this case this year"
label var WNorth_AmericaStateCINC "Continent/region CINC multiplied by polity2 score"
label var WNorth_America_yearlyCINC "All continent/region's weighted CINC scores for this year"
label var WNorth_America_yearlyCINC "The sum of continent/region's weighted CINC scores for each year"
label var StNorth_America_yearlyCINC "Weighted yearly continental/regional CINC scores multiplied by .1"

save regionalCINCE, replace

**Prepare to merge Regional Democratic Strength variable to dataset**

drop stateabb1 cinc1 country1 North_America1 South_America1 Europe1 Africa1  Middle_East1 Far_East1 Northern_Tier1 Atlantic_Coast1 Pacific_Coast1 Central1 Arab_Israeli1 Northern_Rim1 Arabian_Peninsula1 South_Asia1 Southeast_Asia1 East_Asia1 Asian_Archipelago1 AfgPak1 BurmThai1 Koreas1 Maghreb1 West_Africa1 Gulf_of_Guinea1 Central_Lowlands1 Horn_of_Africa1 Central_Highlands1 South_Atlantic_Coast1 Indian_Ocean1 Southern_Africa1 North_AmericaCINC South_AmericaCINC EuropeCINC AfricaCINC Middle_EastCINC Far_EastCINC Northern_TierCINC Atlantic_CoastCINC Pacific_CoastCINC CentralCINC Arab_IsraeliCINC Northern_RimCINC Arabian_PeninsulaCINC South_AsiaCINC Southeast_AsiaCINC East_AsiaCINC Asian_ArchipelagoCINC BurmThaiCINC KoreasCINC MaghrebCINC West_AfricaCINC Gulf_of_GuineaCINC Central_LowlandsCINC Horn_of_AfricaCINC Central_HighlandsCINC South_Atlantic_CoastCINC Indian_OceanCINC Southern_AfricaCINC North_America_yearlyCINC South_America_yearlyCINC Europe_yearlyCINC Africa_yearlyCINC Middle_East_yearlyCINC Far_East_yearlyCINC Northern_Tier_yearlyCINC Atlantic_Coast_yearlyCINC Pacific_Coast_yearlyCINC Central_yearlyCINC Arab_Israeli_yearlyCINC Northern_Rim_yearlyCINC Arabian_Peninsula_yearlyCINC South_Asia_yearlyCINC Southeast_Asia_yearlyCINC East_Asia_yearlyCINC Asian_Archipelago_yearlyCINC BurmThai_yearlyCINC Koreas_yearlyCINC Maghreb_yearlyCINC West_Africa_yearlyCINC Gulf_of_Guinea_yearlyCINC Central_Lowlands_yearlyCINC Horn_of_Africa_yearlyCINC Central_Highlands_yearlyCINC South_Atlantic_Coast_yearlyCINC Indian_Ocean_yearlyCINC Southern_Africa_yearlyCINC scode2 democ1 autoc1 polity2a North_AmericaStateCINC South_AmericaStateCINC EuropeStateCINC AfricaStateCINC Middle_EastStateCINC Far_EastStateCINC Northern_TierStateCINC Atlantic_CoastStateCINC Pacific_CoastStateCINC CentralStateCINC Arab_IsraeliStateCINC Northern_RimStateCINC Arabian_PeninsulaStateCINC South_AsiaStateCINC Southeast_AsiaStateCINC East_AsiaStateCINC Asian_ArchipelagoStateCINC BurmThaiStateCINC KoreasStateCINC MaghrebStateCINC Gulf_of_GuineaStateCINC West_AfricaStateCINC Central_LowlandsStateCINC Horn_of_AfricaStateCINC Central_HighlandsStateCINC South_Atlantic_CoastStateCINC Indian_OceanStateCINC Southern_AfricaStateCINC WNorth_AmericaStateCINC WSouth_AmericaStateCINC WEuropeStateCINC WAfricaStateCINC WMiddle_EastStateCINC WFar_EastStateCINC WNorthern_TierStateCINC WAtlantic_CoastStateCINC WPacific_CoastStateCINC WCentralStateCINC WArab_IsraeliStateCINC WNorthern_RimStateCINC WArabian_PeninsulaStateCINC WSouth_AsiaStateCINC WSoutheast_AsiaStateCINC WEast_AsiaStateCINC WAsian_ArchipelagoStateCINC WBurmThaiStateCINC WKoreasStateCINC WMaghrebStateCINC WWest_AfricaStateCINC WGulf_of_GuineaStateCINC WCentral_LowlandsStateCINC WHorn_of_AfricaStateCINC WCentral_HighlandsStateCINC WSouth_Atlantic_CoastStateCINC WIndian_OceanStateCINC WSouthern_AfricaStateCINC WNorth_America_yearlyCINC WSouth_America_yearlyCINC WEurope_yearlyCINC WAfrica_yearlyCINC WMiddle_East_yearlyCINC WFar_East_yearlyCINC WNorthern_Tier_yearlyCINC WAtlantic_Coast_yearlyCINC WPacific_Coast_yearlyCINC WCentral_yearlyCINC WArab_Israeli_yearlyCINC WNorthern_Rim_yearlyCINC WArabian_Peninsula_yearlyCINC WSouth_Asia_yearlyCINC WSoutheast_Asia_yearlyCINC WEast_Asia_yearlyCINC WAsian_Archipelago_yearlyCINC WBurmThai_yearlyCINC WKoreas_yearlyCINC WMaghreb_yearlyCINC WWest_Africa_yearlyCINC WGulf_of_Guinea_yearlyCINC WCentral_Lowlands_yearlyCINC WHorn_of_Africa_yearlyCINC WCentral_Highlands_yearlyCINC WSouth_Atlantic_Coast_yearlyCINC WIndian_Ocean_yearlyCINC WSouthern_Africa_yearlyCINC 

sort ccode1 year

save regional_Dem_StrengthE, replace

use regdemE

sort ccode1 year

merge ccode1 year using regional_Dem_StrengthE

drop _merge

save regdemE, replace

**Create one Democratic continental/regional strength variable**

gen continental_demstrength = 0

replace continental_demstrength = StNorth_America_yearlyCINC if North_America== 1

replace continental_demstrength = StSouth_America_yearlyCINC if South_America== 1

replace continental_demstrength = StEurope_yearlyCINC if Europe== 1

replace continental_demstrength = StAfrica_yearlyCINC if Africa== 1

replace continental_demstrength = StMiddle_East_yearlyCINC if Middle_East== 1

replace continental_demstrength = StFar_East_yearlyCINC if Far_East== 1

gen regional_demstrength = 0

replace regional_demstrength = StNorthern_Tier_yearlyCINC if Northern_Tier== 1

replace regional_demstrength = StAtlantic_Coast_yearlyCINC if Atlantic_Coast== 1

replace regional_demstrength = StPacific_Coast_yearlyCINC if Pacific_Coast== 1

replace regional_demstrength = StCentral_yearlyCINC if Central== 1

replace regional_demstrength = StArab_Israeli_yearlyCINC if Arab_Israeli== 1

replace regional_demstrength = StNorthern_Rim_yearlyCINC if Northern_Rim== 1

replace regional_demstrength = StArabian_Peninsula_yearlyCINC if Arabian_Peninsula== 1

replace regional_demstrength = StSouth_Asia_yearlyCINC if South_Asia== 1

replace regional_demstrength = StSoutheast_Asia_yearlyCINC if Southeast_Asia== 1

replace regional_demstrength = StEast_Asia_yearlyCINC if East_Asia== 1

replace regional_demstrength = StAsian_Archipelago_yearlyCINC if Asian_Archipelago== 1

replace regional_demstrength = StMaghreb_yearlyCINC if Maghreb== 1

replace regional_demstrength = StWest_Africa_yearlyCINC if West_Africa== 1

replace regional_demstrength = StGulf_of_Guinea_yearlyCINC if Gulf_of_Guinea== 1

replace regional_demstrength = StCentral_Lowlands_yearlyCINC if Central_Lowlands== 1

replace regional_demstrength = StHorn_of_Africa_yearlyCINC if Horn_of_Africa== 1

replace regional_demstrength = StCentral_Highlands_yearlyCINC if Central_Highlands== 1

replace regional_demstrength = StSouthAtlanticCoast_yearlyCINC if South_Atlantic_Coast== 1

replace regional_demstrength = StIndian_Ocean_yearlyCINC if Indian_Ocean== 1

replace regional_demstrength = StSouthern_Africa_yearlyCINC if Southern_Africa== 1

replace regional_demstrength = StBurmThai_yearlyCINC if BurmThai== 1

replace regional_demstrength = StKoreas_yearlyCINC if Koreas == 1

drop StNorth_America_yearlyCINC StSouth_America_yearlyCINC StEurope_yearlyCINC StAfrica_yearlyCINC StMiddle_East_yearlyCINC StFar_East_yearlyCINC StNorthern_Tier_yearlyCINC StAtlantic_Coast_yearlyCINC StPacific_Coast_yearlyCINC StCentral_yearlyCINC StArab_Israeli_yearlyCINC StNorthern_Rim_yearlyCINC StArabian_Peninsula_yearlyCINC StSouth_Asia_yearlyCINC StSoutheast_Asia_yearlyCINC StEast_Asia_yearlyCINC StAsian_Archipelago_yearlyCINC StBurmThai_yearlyCINC StKoreas_yearlyCINC StMaghreb_yearlyCINC StWest_Africa_yearlyCINC StGulf_of_Guinea_yearlyCINC StCentral_Lowlands_yearlyCINC StHorn_of_Africa_yearlyCINC StCentral_Highlands_yearlyCINC StSouthAtlanticCoast_yearlyCINC StIndian_Ocean_yearlyCINC StSouthern_Africa_yearlyCINC 

save regdemE, replace

drop dup 

sort ccode1 ccode2 year

unab vlist : _all

sort `vlist'

quietly by `vlist': gen dup = cond(_N==1, 0, _n)

count if dup>1

**Repeated identical MIDs in a single year**

drop if dup>1

sort ccode1 ccode2 year

duplicates report ccode1 ccode2 year

duplicates list ccode1 ccode2 year

gen dyadcode = ccode1*1000 + ccode2

drop if dyadcode==.

**multiple observations exist per year because of the MID data **
**I give a preference for an observation with a war present if the other duplicates do not**

sort dyadcode year

gen duplicate = 0

replace duplicate = 1 if dyadcode==dyadcode[_n-1] & year==year[_n-1]

drop if duplicate==1 & war==0

gen duplicate2 = 0

replace duplicate2 = 1 if dyadcode==dyadcode[_n+1] & year==year[_n+1]

drop if duplicate2==1 & war==0

duplicates list ccode1 ccode2 year

**These duplicates are when contiguity changes, or some other unused stats are different - I go with the original values during the observed year**

drop if duplicate == 1 & dyadcode == dyadcode[_n-1] & year == year[_n-1]

**declare paneldata**

sort ccode1 ccode2 year

xtset dyadcode year

drop dup duplicate duplicate2

save regdemE, replace

**create dissimilarity variable**

drop if democ1==-66 & democ1[_n-1]==-66

drop if democ2==-66 & democ2[_n-1]==-66

replace democ1 = democ1[_n-1] if democ1==-66

replace autoc1 = autoc1[_n-1] if autoc1==-66

replace democ2 = democ2[_n-1] if democ2==-66

replace autoc2 = autoc2[_n-1] if autoc2==-66

gen dissimilarity = abs(democ1-democ2)+abs(autoc1-autoc2)

replace dissimilarity = abs(polity2a - polity2b) if dissimilarity>20

save regdemE, replace

**Joint Autocracy values**

egen JointAutoc = rowmin(autoc1 autoc2)

save regdemE, replace

**Rivalry data set Thompson, William R. (2001) Identifying Rivals and Rivalries in World Politics. International Studies Quarterly 45 (4): 557-586.**

use rivals

sort ccode1 ccode2 year

save rivals, replace

use regdemE

sort ccode1 ccode2 year

merge ccode1 ccode2 year using rivals

drop _merge

gen rivals = 1

replace rivals = 0 if rivalrydyad==. & year<2001

replace rivals = . if year>2000

drop rivalrydyad

gen MID = 0

replace MID = 1 if hihost>0

**generate regional codes**

gen intercontinental = 0

replace intercontinental = 1 if North_America== 0 & South_America== 0 & Europe== 0 & Africa== 0 & Middle_East== 0 & Far_East== 0

gen continentalcode = 0

replace continentalcode = 1 if North_America== 1

replace continentalcode = 2 if South_America== 1

replace continentalcode = 3 if Europe== 1

replace continentalcode = 4 if Africa== 1

replace continentalcode = 5 if Middle_East== 1

replace continentalcode = 6 if Far_East== 1

replace continentalcode = 7 if intercontinental== 1

replace continentalcode = . if continentalcode== 0

gen interregional = 0

replace interregional = 1 if Northern_Tier== 0 & Atlantic_Coast== 0 & Pacific_Coast== 0 & Central== 0 & Arab_Israeli== 0 & Northern_Rim== 0 & Arabian_Peninsula== 0 & South_Asia== 0 & Southeast_Asia== 0 & East_Asia== 0 & Asian_Archipelago== 0 & Maghreb== 0 & West_Africa== 0 & Gulf_of_Guinea== 0 & Central_Lowlands== 0 & Horn_of_Africa== 0 & Central_Highlands== 0 & South_Atlantic_Coast== 0 & Indian_Ocean== 0 & Southern_Africa== 0

gen regionalcode = 0

replace regionalcode = 1 if Northern_Tier== 1

replace regionalcode = 2 if Atlantic_Coast== 1

replace regionalcode = 3 if Pacific_Coast== 1

replace regionalcode = 4 if Central== 1

replace regionalcode = 5 if Arab_Israeli== 1

replace regionalcode = 6 if Northern_Rim== 1

replace regionalcode = 7 if Arabian_Peninsula== 1

replace regionalcode = 8 if South_Asia== 1

replace regionalcode = 9 if Southeast_Asia== 1

replace regionalcode = 10 if East_Asia== 1

replace regionalcode = 11 if Asian_Archipelago== 1

replace regionalcode = 12 if Maghreb== 1

replace regionalcode = 13 if West_Africa== 1

replace regionalcode = 14 if Gulf_of_Guinea== 1

replace regionalcode = 15 if Central_Lowlands== 1

replace regionalcode = 16 if Horn_of_Africa== 1

replace regionalcode = 17 if Central_Highlands== 1

replace regionalcode = 18 if South_Atlantic_Coast== 1

replace regionalcode = 19 if Indian_Ocean== 1

replace regionalcode = 20 if Southern_Africa== 1

replace interregional =0 if North_America==1 | Europe==1

replace regionalcode = 21 if interregional==1

replace regionalcode = 22 if BurmThai==1

replace regionalcode = 23 if Koreas==1

replace regionalcode =. if regionalcode==0

rename conttype contiguous

gen land_contiguity = 0

gen water_contiguity = 0

replace land_contiguity = 1 if contiguous == 1

replace water_contiguity = 1 if contiguous >1 & contiguous < 6

**gen interaction variables**

gen interact_cont_autoc = continental_demstrength*JointAutoc

gen interact_cont_diss = continental_demstrength*dissimilarity

gen interact_region_autoc = regional_demstrength*JointAutoc

gen interact_region_diss = regional_demstrength*dissimilarity

replace JointAutoc=0 if JointAutoc<0

save regdemE, replace

***Issues data (dyad-year version)Hensel 2001; Hensel and Mitchell 2005; Hensel, Mitchell, Sowers II, and Thyne 2008***

use dyadic_terriss, replace

sort dyadcode year

save dyadic_terriss, replace

use regdemE

sort dyadcode year

merge dyadcode year using dyadic_terriss

replace icowsal = 0 if icowsal==. & year<=2001

save regdemE, replace

**Maoz conflict data**

use dyadicmid2.0MAOZ.dta

keep statea stateb strtyr war

gen dyadcode = (statea*1000) + stateb

sort dyadcode strtyr

rename strtyr year

drop statea stateb

rename war Mwar

gen MMID = 1

count if year==year[_n-1] & dyadcode == dyadcode[_n-1]

unab vlist : _all

sort `vlist'

quietly by `vlist': gen dup = cond(_N==1, 0, _n)

count if dup>1

drop if dup>1

drop dup

sort dyadcode year

save maozmidE, replace

use regdemE

sort dyadcode year

drop _merge

merge dyadcode year using maozmid

replace MMID = 0 if MMID == .

replace Mwar = 0 if Mwar == .

**************************************
**Models using Maoz's data, see models on COW data for one's in paper**
**Without inter-continental/inter-regional dyads**
**************************************

tab regionalcode

tab continentalcode

drop _merge

drop if year<1870

replace continentalcode = . if continentalcode == 7

replace regionalcode =. if regionalcode==0

replace regionalcode = . if regionalcode == 21

drop dup

tab regionalcode

tab continentalcode

sort dyadcode year

count if dyadcode==dyadcode[_n-1] & year==year[_n-1] & MID==MID[_n-1]

drop if dyadcode==dyadcode[_n-1] & year==year[_n-1] & MID==MID[_n-1]

tab regionalcode

tab continentalcode

save regdemE, replace

**************************************
**Models using COW data**
**Without inter-continental/inter-regional dyads**
*************************************

***TABLE 1: Model 1**

logit MID land_contiguity water_contiguity rivals icowsal JointAutoc dissimilarity if regionalcode!=. 

predict M1

roctab MID M1

brier MID M1

***TABLE 1: Model 2**

corr dissimilarity JointAutoc water_contiguity regional_demstrength if regionalcode!=.

logit MID land_contiguity water_contiguity rivals icowsal JointAutoc dissimilarity regional_demstrength if regionalcode!=.

***TABLE 1: Model 3**

xtmelogit MID land_contiguity water_contiguity rivals icowsal dissimilarity if year < 1985 || regionalcode:, cov(unstruct)

estat recovariance, correlation
  
estat icc

predict D2 if year>=1984

roctab MID D2

brier MID D2 if year>=1984

***TABLE 1: Model 4**

xtmelogit MID land_contiguity water_contiguity rivals icowsal dissimilarity interact_region_diss if year < 1985 || regionalcode: regional_demstrength, cov(unstruct)

estat recovariance, correlation
  
estat icc

predict D5 if year>1984

roctab MID D5

brier MID D5 if year>1984

***TABLE 1: Model 5**

xtmelogit MID land_contiguity water_contiguity rivals icowsal JointAutoc dissimilarity  interact_region_diss|| regionalcode: regional_demstrength, cov(unstruct)

estat recovariance, correlation
  
estat icc

estat group

predict M3

roctab MID M3

brier MID M3

**Comparing ROC curves for TABLE 2**

roccomp MID M1 M3, summary

roccomp MID D2 D5, summary

**Continental Codes for APPENDIX B**

***APPENDIX B: Model 1**

xtmelogit MID land_contiguity water_contiguity rivals JointAutoc icowsal dissimilarity interact_cont_diss|| continentalcode: continental_demstrength, cov(unstruct)

estat recovariance, correlation

estat icc

**APPENDIX B: Model 2**

xtmelogit MID land_contiguity water_contiguity rivals icowsal dissimilarity interact_cont_diss|| continentalcode: continental_demstrength, cov(unstruct)

estat recovariance, correlation

estat icc

**APPENDIX B: Model 3**

xtmelogit war land_contiguity water_contiguity rivals JointAutoc icowsal dissimilarity interact_cont_diss|| continentalcode: continental_demstrength, cov(unstruct)

estat recovariance, correlation

estat icc

**APPENDIX B: Model 4**

xtmelogit war land_contiguity water_contiguity rivals icowsal dissimilarity interact_cont_diss|| continentalcode: continental_demstrength, cov(unstruct)

estat recovariance, correlation

estat icc

save simregE.dta, replace

**-------------------------------------**
**SimregE is created so I can have a separate dataset for marginal effect graphs.  It includes the same data used for the models in table 1**
**See MEDissimilarityE.do for marginal effect graph on dissimilarity - figure 3**
**-------------------------------------**

***Robustness checks with Maoz MID data*****

******Robustness test with Maoz MIDs - regular logit**

logit MMID land_contiguity water_contiguity rivals icowsal JointAutoc dissimilarity if regionalcode!=. 

******Robustness test with Maoz MIDs full model***

xtmelogit MMID land_contiguity water_contiguity icowsal rivals JointAutoc dissimilarity  interact_region_diss|| regionalcode: regional_demstrength, cov(unstruct)

estat recovariance, correlation
  
estat icc

***Robustness test with Maoz MIDs w/o Joint Autoc**

xtmelogit MMID land_contiguity water_contiguity icowsal rivals dissimilarity  interact_region_diss|| regionalcode: regional_demstrength, cov(unstruct)

estat recovariance, correlation
  
estat icc
